document.addEventListener('DOMContentLoaded', function() {
  chrome.runtime.sendMessage({ action: 'getUrlLevels' }, function(response) {
    if (response) {
      var levelsContainer = document.getElementById('levels');
      var levels = [
        { label: 'Protocol', value: response.protocol },
        { label: 'Hostname', value: response.hostname },
        { label: 'Port', value: response.port },
        { label: 'Pathname', value: response.pathname },
        { label: 'Search Params', value: response.search },
        { label: 'Hash', value: response.hash }
      ];

      levels.forEach(level => {
        var div = document.createElement('div');
        div.className = 'level';
        div.textContent = `${level.label}: ${level.value}`;
        levelsContainer.appendChild(div);
      });
 
      document.getElementById('levels').textContent =JSON.stringify(response)

      // 将URL层级信息存储在chrome.storage中以便election-vite使用
      chrome.storage.local.set({ urlLevels: response });

      
    }else{
      document.getElementById('levels').textContent =JSON.stringify('no data')

    }
  });
});
  